#!/bin/bash
set -e

WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BASEOUT="$WDIR/Ocean"
BASEOUTTAR="$WDIR/Ocean.tar.gz"
BASEOUTCFG="$WDIR/OceanCfg"

#Proto files
BASEPROTOSRC="$WDIR/../protobuffer"
BASEPROTOOUT="$BASEOUT/protobuffer"

#webServer params
WEBSERVERSRC="$WDIR/../server"
WEBSERVEROUT="$BASEOUT/server"
WEBSERVERCFG="$WDIR/webServerCfg"

#gserver params
GSERVERSRC="$WDIR/../gserver/bin"
GSERVEROUT="$BASEOUT/gserver"

#make output directory
if [ -d $BASEOUT ]; then
    rm -rf $BASEOUT
fi
mkdir $BASEOUT

#publish webServer
cp -r $WEBSERVERSRC $WEBSERVEROUT
if [ -d $WEBSERVERCFG ]; then
   cp -r $WEBSERVERCFG/* $WEBSERVEROUT
fi

#publish gserver
cp -r $GSERVERSRC $GSERVEROUT

#rm -rf $LANSERVEROUT/public/cfgs
#mkdir $LANSERVEROUT/public/cfgs
#rm -rf $LANSERVEROUT/public/apks
#mkdir $LANSERVEROUT/public/apks
#rm -rf $LANSERVEROUT/public/tmp
#mkdir $LANSERVEROUT/public/tmp

#copy proto
mkdir $BASEPROTOOUT
cp $BASEPROTOSRC/*.desc $BASEPROTOOUT/

#copy base cfg
if [ -d $BASEOUTCFG ]; then
   cp -r $BASEOUTCFG/* $BASEOUT
fi


tar cpzf $BASEOUTTAR -C `dirname $BASEOUT` `basename $BASEOUT`
rm -rf $BASEOUT
